<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="okhttp3.*" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.interfaces.zhlx.duss.utils.SrmUtil" %>
<%@ page import="java.util.concurrent.TimeUnit" %>
<%--OA流程节点信息SRM系统接口回传--%>
<%
    RecordSet rs = new RecordSet();
    String requestid ="4090093";
    int formid = Util.getIntValue("-4199");
    formid = Math.abs(formid);
    String src = Util.null2String(request.getParameter("src"));
    String remark = Util.null2String(request.getParameter("remark"));
    try {
        rs.executeQuery("select htly,spbh from formtable_main_" + formid + " where requestid=?", requestid);
        rs.next();
        String htly = Util.null2String(rs.getString("htly"));
        String spbh = Util.null2String(rs.getString("spbh"));
        if (!"0".equals(htly)) {
            JSONObject paramJson = new JSONObject();
            String operatorStatus = "approve";
            String zt = "approving";
            int nextnodeid = 0;
            rs.executeQuery("select distinct userid,nodeid from workflow_currentoperator\n" +
                    " where (isremark in ('0','1','5','7','8','9') or (isremark='4' and viewtype=0))  and requestid = ?", requestid);
            while (rs.next()) {
                nextnodeid = Util.getIntValue(rs.getString("nodeid"));
            }
            JSONObject reusltJson = SrmUtil.getNodebaseNodename(nextnodeid);
            String nodename = Util.null2String(reusltJson.getString("nodename"));
            String isend = Util.null2String(reusltJson.getString("isend"));
            if ("1".equals(isend) || "经办人归档".equals(nodename) ||"电子经办人归档".equals(nodename)) {
                zt = "approve";
            } else {
                if ("reject".equals(src)) {
                    operatorStatus = "notApproved";
                    if ("退回归档勿修改".equals(nodename)) {
                        zt = "notApproved";
                    }
                }
            }
            paramJson.put("oaId", requestid);
            paramJson.put("operatorStatus", operatorStatus);
            paramJson.put("operatorNode", nodename);
            paramJson.put("status", zt);
            paramJson.put("remark", SrmUtil.removeHTMLTags(remark));
            paramJson.put("spbh", spbh);
            out.print(">>>>>WeaCghjlcBackAction>>>>>paramJson=" + paramJson+"<br/>");
            try {
                OkHttpClient client = new OkHttpClient().newBuilder()
                        .connectTimeout(60, TimeUnit.SECONDS)
                        .readTimeout(60, TimeUnit.SECONDS)
                        .writeTimeout(60, TimeUnit.SECONDS)
                        .build();
                MediaType mediaType = MediaType.parse("application/json");
                RequestBody body = RequestBody.create(mediaType, paramJson.toJSONString());
                Request req = new Request.Builder()
                        .url("http://10.214.11.120:30006/api/oa/handleoadate")
                        .method("POST", body)
                        .addHeader("Content-Type", "application/json")
                        .build();
                Response resp = client.newCall(req).execute();
                String result = Util.null2String(resp.body().string());
               out.print(">>>>>WeaCghjlcBackAction>>>>>result=" + result+"<br/>");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
%>

<%!

%>


